from manim import *
from numpy import flip, insert

LV,QL,QH,JH='#75cfb8','#bbdfc8','#f0e5d8','#ffc478'

class p1(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        radius=5
        ellipse=Ellipse(radius*2,3).shift(DOWN*2)
        o=ellipse.get_center()
        arc6=Arc(radius,0,PI,arc_center=o)
        # cube
        high=4
        xxx=np.sqrt(radius**2-high**2)
        a,b,c,d=o+LEFT*xxx+UP*high,[-0.1,2.8,0],o+RIGHT*xxx+UP*high,[0.1,1,0]
        a_,c_,d_=a+DOWN*high,c+DOWN*high,d+DOWN*high
        aa_,cc_,dd_,a_d_,c_d_=Line(a,a_),Line(c,c_),Line(d,d_),Line(a_,d_),Line(c_,d_)
        o=(a+c)/2
        oc_=Line(o,c_).set_color(LV)
        abcd=Polygon(a,b,c,d)
        self.add(oc_,ellipse,arc6,abcd,aa_,cc_,dd_,a_d_,c_d_,
            DashedLine(a,c),
            DashedLine(b,d),
            
        )
        self.wait()

class p2(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        radius=5
        ellipse=Ellipse(radius*2,3).shift(DOWN*2)
        o=ellipse.get_center()
        arc6=Arc(radius,0,PI,arc_center=o)
        # cube
        high=4
        xxx=np.sqrt(radius**2-high**2)
        a,b,c,d=o+LEFT*xxx+UP*high,[-0.2,2.8,0],o+RIGHT*xxx+UP*high,[0.2,1,0]
        a_,c_,d_=a+DOWN*high,c+DOWN*high,d+DOWN*high
        aa_,cc_,dd_,a_d_,c_d_=Line(a,a_),Line(c,c_),Line(d,d_),Line(a_,d_),Line(c_,d_)
        o=(a+c)/2
        oc_=Line(o,c_).set_color(LV)
        abcd=Polygon(a,b,c,d)
        self.add(oc_,ellipse,arc6,abcd,aa_,cc_,dd_,a_d_,c_d_,
            DashedLine(a,c),
            DashedLine(b,d)
        )
        # p2
        o_=o+DOWN*high
        co_=Line(c,o_).set_color(JH)
        self.add(co_,
            DashedLine(a_,c_),
            DashedLine(o,o_),
            dd_
        )
        self.wait()

class p3(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        s_red=Square(4).stretch(2,1).set_fill(RED,1).set_stroke(WHITE)
        s1=s_red.copy().shift(LEFT*6)
        s2=s_red.copy().shift(RIGHT*6)
        self.add(s1,s2)
        #
        radius=6
        arc=Arc(radius,0,PI/2).shift(DL*3)
        d=[-3,-3,0]
        self.add(arc,Line(d,d+UP*radius),Line(d,d+RIGHT*radius))
        c=[0,-3,0]
        b=c+UP*3*np.sqrt(3)
        a=b+LEFT*3
        self.add(Polygon(a,b,c),Line(a,c).set_color(LV),
            MathTex('A').next_to(a,LEFT),
            MathTex('B').next_to(b,UR),
            MathTex('C').next_to(c,DOWN),
            MathTex('D').next_to(d,DOWN),
            MathTex('5').move_to([-1.5,-3.3,0]),
            MathTex('5').move_to([1.5,-3.3,0]),
        )
        self.wait()

class p4(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        s_red=Square(4).stretch(2,1).set_fill(RED,1).set_stroke(WHITE)
        s1=s_red.copy().shift(LEFT*6)
        s2=s_red.copy().shift(RIGHT*6)
        self.add(s1,s2)
        #
        radius=6
        arc=Arc(radius,0,PI/2).shift(DL*3)
        d=[-3,-3,0]
        self.add(arc,Line(d,d+UP*radius),Line(d,d+RIGHT*radius))
        c=[0,-3,0]
        b=c+UP*3*np.sqrt(3)
        a=b+LEFT*3
        self.add(Polygon(a,b,c),Line(a,c).set_color(LV),Line(b,d).set_color(JH),
            MathTex('A').next_to(a,LEFT),
            MathTex('B').next_to(b,UR),
            MathTex('C').next_to(c,DOWN),
            MathTex('D').next_to(d,DOWN),
            MathTex('5').move_to([-1.5,-3.3,0]),
            MathTex('5').move_to([1.5,-3.3,0]),
        )
        self.wait()